package com.nuanshui.heatedloan.credit.service;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.baseservice.service.CommonServiceImpl;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.credit.dal.mapper.CustomerPeopleRelationshipMapper;
import com.nuanshui.heatedloan.credit.facade.CustomerPeopleRelationshipService;
import com.nuanshui.heatedloan.credit.form.CustomerPeopleRelationshipForm;
import com.nuanshui.heatedloan.credit.vo.CustomerPeopleRelationshipVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by wangxw on 2017/6/27.
 */
@Service(ServiceConstant.CUSTOMERPEOPLERELATIONSHIPSERVICE)
@Transactional(readOnly=true,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
public class CustomerPeopleRelationshipServiceImpl extends CommonServiceImpl implements CustomerPeopleRelationshipService {


    @Autowired
    private CustomerPeopleRelationshipMapper customerPeopleRelationshipMapper;

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public void saveCustomerPeopleRelationship(CustomerPeopleRelationshipForm customerPeopleRelationshipForm) {
        customerPeopleRelationshipMapper.saveCustomerPeopleRelationship(customerPeopleRelationshipForm);
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public void updateCustomerPeopleRelationship(CustomerPeopleRelationshipForm customerPeopleRelationshipForm) {
        customerPeopleRelationshipMapper.updateCustomerPeopleRelationship(customerPeopleRelationshipForm);
    }

    @Override
    public CustomerPeopleRelationshipVO loadVO(String id) {
        CustomerPeopleRelationshipVO customerPeopleRelationshipVO=new CustomerPeopleRelationshipVO();
        customerPeopleRelationshipMapper.loadVO(id);
        return customerPeopleRelationshipVO;
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public void deleteCustomerPeopleRelationship(String id) {
        customerPeopleRelationshipMapper.deleteCustomerPeopleRelationship(id);
    }

    @Override
    public List<CustomerPeopleRelationshipVO> loadcustomerPeopleRelationshipVOByCusId(String userId) {
        List<CustomerPeopleRelationshipVO> customerPeopleRelationshipVOs=
        customerPeopleRelationshipMapper.loadcustomerPeopleRelationshipVOByCusId(userId);
        if(customerPeopleRelationshipVOs!=null&&customerPeopleRelationshipVOs.size()>0){
            return customerPeopleRelationshipVOs;
        }
        return null;
    }
}
